/*
 * Copyright (C) 2021 The Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package com.oushangfeng.pinneddemo.custom.data;

import com.oushangfeng.pinneddemo.ResourceTable;
import com.oushangfeng.pinneddemo.custom.categorylist.CategoryItemFactory;
import com.oushangfeng.pinneddemo.custom.categorylist.CommonCategory;
import com.oushangfeng.pinneddemo.custom.categorylist.HeadItem;
import com.oushangfeng.pinneddemo.custom.categorylist.SingleListItem;
import com.oushangfeng.pinneddemo.custom.categorylist.SmallLabelItem;
import com.oushangfeng.pinneddemo.custom.categorylist.StockHeadItem;
import com.oushangfeng.pinneddemo.custom.categorylist.StockListItem;
import com.oushangfeng.pinneddemo.custom.categorylist.StockTitleItem;
import com.oushangfeng.pinneddemo.datainterface.CategoryItemBase;
import com.oushangfeng.pinnedsectionitemdecoration.callback.datainterface.Category;

import ohos.app.Context;

import java.util.ArrayList;
import java.util.List;

/**
 * CustomData
 *
 * @since 2021-03-27
 * Created by oubowu on 2021/3/27 10:29
 */
public class CustomData {
    /**
     * M_DOGS
     */
    public final int[] M_DOGS = {HeadItem.ITEM_TYPE, ResourceTable.Media_dog0, ResourceTable.Media_dog1,
        ResourceTable.Media_dog2, ResourceTable.Media_dog3, ResourceTable.Media_dog4,
        ResourceTable.Media_dog5, ResourceTable.Media_dog6, ResourceTable.Media_dog7, ResourceTable.Media_dog8};
    /**
     * M_CATS
     */
    public final int[] M_CATS = {HeadItem.ITEM_TYPE, ResourceTable.Media_cat0, ResourceTable.Media_cat1,
        ResourceTable.Media_cat2, ResourceTable.Media_cat3, ResourceTable.Media_cat4, ResourceTable.Media_cat5,
        ResourceTable.Media_cat6, ResourceTable.Media_cat7, ResourceTable.Media_cat8};
    /**
     * M_CRABBITS
     */
    public final int[] M_CRABBITS = {
        HeadItem.ITEM_TYPE, ResourceTable.Media_rabbit0, ResourceTable.Media_rabbit1,
        ResourceTable.Media_rabbit2, ResourceTable.Media_rabbit3, ResourceTable.Media_rabbit4,
        ResourceTable.Media_rabbit5, ResourceTable.Media_rabbit6, ResourceTable.Media_rabbit7,
        ResourceTable.Media_rabbit8};
    /**
     * M_PANDAS
     */
    public final int[] M_PANDAS = {HeadItem.ITEM_TYPE, ResourceTable.Media_panda0, ResourceTable.Media_panda1,
        ResourceTable.Media_panda2, ResourceTable.Media_panda3, ResourceTable.Media_panda4,
        ResourceTable.Media_panda5, ResourceTable.Media_panda6, ResourceTable.Media_panda7,
        ResourceTable.Media_panda8};
    /**
     * PIC_TITLE
     */
    public final String[] PIC_TITLE = {"Dog", "Cat", "Rabbit", "Panda"};
    /**
     * PIC_ANI
     */
    public final int[][] PIC_ANI = {M_DOGS, M_CATS, M_CRABBITS, M_PANDAS};
    /**
     * STOCK_TITLE_HEAD
     */
    public String[] stockTitleHead = {""};
    /**
     * STOCK_TITLE
     */
    public String[] stockTitle = {"", "涨幅榜", "跌幅榜", "换手率", "振幅榜"};
    /**
     * UP
     */
    public String[] up = {"宝利国际,600300,5.37,+10.04%", "西安旅游,000610,14.14,+10.04%",
        "安徽合力,600761,11.4,+10.04%", "通产丽星,002243,14.47,+10.04%", "海波重科,300517,21.18,+10.03%",
        "杭电股份,603618,15.15,+10.02%", "吉宏股份,002803,21.64,+10.02%", "西安饮食,000721,8.13,+10.01%",
        "上海临港,600848,21.98,+10.01%", "星河生物,300143,24.84,+10.01%"};
    /**
     * down
     */
    public String[] down = {"万方发展,000638,24.75,-10.00%", "新 海 宜,002089,19.35,-10.00%",
        "苏州设计,300500,97.57,-10.00%", "先导智能,300450,42.07,-9.99%", "亚通股份,600692,16.22,-9.99%",
        "上峰水泥,000672,7.12,-9.99%", "吴通控股,300292,39.67,-9.98%", "*欣泰,300372,5.08,-9.93%",
        "中矿资源,002738,22.75,-9.18%", "合诚股份,603909,62.8,-9.12%"};
    /**
     * change
     */
    public String[] change = {"新光药业,300519,108,+0.52%", "世名科技,300522,94.08,+0.48%",
        "合诚股份,603909,62.8,+0.41%", "新宏泰,603016,42.77,+0.36%", "洪汇新材,002802,58.27,+0.35%",
        "杭电股份,603618,15.15,+0.34%", "三德科技,300515,78.82,+0.31%", "松发股份,603268,53.76,+0.31%",
        "苏州设计,300500,97.57,+0.26%", "微光股份,002801,156,+0.25%"};
    /**
     * AMPLITUDE
     */
    public String[] amplitude = {"盛达矿业,000603,21.85,+16.65%", "松发股份,603268,53.76,+14.84%",
        "神州数码,000034,29.15,+13.47%", "三德科技,300515,78.82,+13.15%", "杭电股份,603618,15.15,+12.49%",
        "康耐特,300061,31.5,+12.44%", "新五丰,600975,10.24,+12.33%", "恒天海龙,000677,6.06,+12.12%",
        "海顺新材,300501,132.41,+11.95%", "力合股份,000532,20.04,+11.50%"};
    /**
     * STOCK_ITEM
     */
    public String[][] stockItem = {stockTitleHead, up, down, change, amplitude};

    private static final int INT_1 = -1;
    private static final int INT_0 = 0;

    /**
     * getCustomData
     *
     * @param context
     * @return List
     */
    public List<Category> getCustomData(Context context) {
        int leftNumber = INT_1;
        ArrayList<Category> categoryList = new ArrayList<>();
        for (int i = 0; i < PIC_ANI.length; i++) {
            ArrayList<CategoryItemBase> itemList = new ArrayList<>();
            for (int j = 0; j < PIC_ANI[i].length; j++) {
                leftNumber++;
                if (PIC_ANI[i][j] == HeadItem.ITEM_TYPE) {
                    itemList.add(CategoryItemFactory.createListItem(
                            context, false, HeadItem.ITEM_TYPE, PIC_TITLE[i] + ""));
                } else {
                    itemList.add(CategoryItemFactory.createListItem(
                            context, false, SingleListItem.ITEM_TYPE,
                            leftNumber + "", PIC_ANI[i][j] + ""));
                }
            }
            CommonCategory commonCategory = new CommonCategory(context, itemList, i);
            categoryList.add(commonCategory);
        }
        return categoryList;
    }

    /**
     * getSmallLabelData
     *
     * @param context
     * @return List
     */
    public List<Category> getSmallLabelData(Context context) {
        int leftNumber = INT_1;
        ArrayList<Category> categoryList = new ArrayList<>();
        for (int i = 0; i < PIC_ANI.length; i++) {
            ArrayList<CategoryItemBase> itemList = new ArrayList<>();
            for (int j = 0; j < PIC_ANI[i].length; j++) {
                if (PIC_ANI[i][j] != HeadItem.ITEM_TYPE) {
                    leftNumber++;
                    if (j == 1) {
                        itemList.add(CategoryItemFactory.createListItem(
                                context, true, SmallLabelItem.ITEM_TYPE,
                                leftNumber + "", PIC_ANI[i][j] + "", j + "," + PIC_TITLE[i]));
                    } else {
                        itemList.add(CategoryItemFactory.createListItem(
                                context, false, SmallLabelItem.ITEM_TYPE,
                                leftNumber + "", PIC_ANI[i][j] + "", j + "," + PIC_TITLE[i]));
                    }
                }
            }
            CommonCategory commonCategory = new CommonCategory(context, itemList, i);
            categoryList.add(commonCategory);
        }
        return categoryList;
    }

    /**
     * getStockData
     *
     * @param context
     * @return List
     */
    public List<Category> getStockData(Context context) {
        ArrayList<Category> categoryList = new ArrayList<>();
        for (int i = 0; i < stockTitle.length; i++) {
            ArrayList<CategoryItemBase> itemList = new ArrayList<>();
            if (stockTitle[i].length() == 0) {
                itemList.add(CategoryItemFactory.createListItem(
                        context, false, StockTitleItem.ITEM_TYPE, stockTitle[i] + ""));
            } else {
                itemList.add(CategoryItemFactory.createListItem(
                        context, true, StockHeadItem.ITEM_TYPE, stockTitle[i] + ""));
            }
            for (int j = 0; j < stockItem[i].length; j++) {
                if (stockItem[i].length > INT_0) {
                    itemList.add(CategoryItemFactory.createListItem(
                            context, false, StockListItem.ITEM_TYPE, stockItem[i][j] + ""));
                }
            }
            CommonCategory commonCategory = new CommonCategory(context, itemList, i);
            categoryList.add(commonCategory);
        }
        return categoryList;
    }
}
